{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Asterisks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countAsterisks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计星号"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串&nbsp;<code>s</code>&nbsp;，每&nbsp;<strong>两个</strong>&nbsp;连续竖线&nbsp;<code>'|'</code>&nbsp;为 <strong>一对</strong>&nbsp;。换言之，第一个和第二个&nbsp;<code>'|'</code>&nbsp;为一对，第三个和第四个&nbsp;<code>'|'</code>&nbsp;为一对，以此类推。</p>\n",
    "\n",
    "<p>请你返回 <strong>不在</strong> 竖线对之间，<code>s</code>&nbsp;中&nbsp;<code>'*'</code>&nbsp;的数目。</p>\n",
    "\n",
    "<p><strong>注意</strong>，每个竖线&nbsp;<code>'|'</code>&nbsp;都会 <strong>恰好</strong>&nbsp;属于一个对。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>s = \"l|*e*et|c**o|*de|\"\n",
    "<b>输出：</b>2\n",
    "<b>解释：</b>不在竖线对之间的字符加粗加斜体后，得到字符串：\"<strong><em>l</em></strong>|*e*et|<strong><em>c**o</em></strong>|*de|\" 。\n",
    "第一和第二条竖线 '|' 之间的字符不计入答案。\n",
    "同时，第三条和第四条竖线 '|' 之间的字符也不计入答案。\n",
    "不在竖线对之间总共有 2 个星号，所以我们返回 2 。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>s = \"iamprogrammer\"\n",
    "<b>输出：</b>0\n",
    "<b>解释：</b>在这个例子中，s 中没有星号。所以返回 0 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>s = \"yo|uar|e**|b|e***au|tifu|l\"\n",
    "<b>输出：</b>5\n",
    "<b>解释：</b>需要考虑的字符加粗加斜体后：\"<strong><em>yo</em></strong>|uar|<strong><em>e**</em></strong>|b|<strong><em>e***au</em></strong>|tifu|<strong><em>l</em></strong>\" 。不在竖线对之间总共有 5 个星号。所以我们返回 5 。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 1000</code></li>\n",
    "\t<li><code>s</code>&nbsp;只包含小写英文字母，竖线&nbsp;<code>'|'</code>&nbsp;和星号&nbsp;<code>'*'</code>&nbsp;。</li>\n",
    "\t<li><code>s</code>&nbsp;包含 <strong>偶数</strong>&nbsp;个竖线&nbsp;<code>'|'</code> 。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-asterisks](https://leetcode.cn/problems/count-asterisks/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-asterisks](https://leetcode.cn/problems/count-asterisks/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"l|*e*et|c**o|*de|\"', '\"iamprogrammer\"', '\"yo|uar|e**|b|e***au|tifu|l\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        vertical_line_num = 0\n",
    "        star_num = 0\n",
    "        for i, c in enumerate(s):\n",
    "            if c == '|':\n",
    "                vertical_line_num = vertical_line_num + 1\n",
    "            else:\n",
    "                if c == '*':\n",
    "                    if vertical_line_num % 2 == 0:\n",
    "                        star_num = star_num + 1\n",
    "        return star_num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        i_count = 0\n",
    "        star_count = 0\n",
    "\n",
    "        for c in s:\n",
    "            if c == \"|\":\n",
    "                i_count += 1\n",
    "                continue\n",
    "            if c == \"*\" and i_count% 2 == 0: \n",
    "                star_count += 1\n",
    "\n",
    "        return star_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        st = ['#']\n",
    "        for c in s:\n",
    "            if st[-1] == '|':\n",
    "                if c != '|':\n",
    "                    continue\n",
    "                else:\n",
    "                    st.pop()\n",
    "            else:\n",
    "                st.append(c)\n",
    "        \n",
    "        return sum(s == '*' for s in st)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        flag = True\n",
    "        count = 0\n",
    "        for c in s:\n",
    "            if c == \"|\":\n",
    "                flag = not flag\n",
    "                continue\n",
    "            if flag:\n",
    "                count += int(c == \"*\")\n",
    "        \n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        return sum(ss.count('*') for ss in s.split('|')[::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        # 遍历字符串，找到符合条件的字符，记录字出现的次数\n",
    " \n",
    "        res = 0 # 记录符合条件的字符个数\n",
    "        length = len(s) # 获取字符串长度\n",
    "        i = 0\n",
    "        count = 0\n",
    "        '''\n",
    "        count = 0 记录 字符\"|\"出现多少次\n",
    "        当count是偶数时出现的 \"*\"字符都会被记录\n",
    "        当count为奇数\"*\"不会被记录\n",
    "        '''\n",
    "        while i < length:\n",
    "            if s[i] == '|':\n",
    "                count += 1\n",
    "            if s[i] =='*' and count % 2 == 0:\n",
    "                res += 1    \n",
    "            i += 1\n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        return re.compile(r'\\|.*?\\|').sub('', s).count('*')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "      sum_str=0\n",
    "      l=0\n",
    "      for i in s:\n",
    "        if i=='|' and l==0:\n",
    "          l=1\n",
    "          continue\n",
    "        elif i=='|' and l==1:\n",
    "          l=0\n",
    "          continue\n",
    "        if l==0:\n",
    "          if i =='*':\n",
    "            sum_str+=1\n",
    "      return sum_str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        x=1\n",
    "        sum=0\n",
    "        for i in range(len(s)):\n",
    "            if x==1 and s[i]=='*':\n",
    "                sum+=1\n",
    "            if s[i]=='|':\n",
    "                x*=(-1)\n",
    "        return sum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        slist = s.split(\"|\")\n",
    "        for i in range(0, len(slist)+1):\n",
    "            if (i+1) % 2 == 1:\n",
    "                starlist = list(slist[i])\n",
    "                for element in starlist:  \n",
    "                    if element == '*':\n",
    "                        ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        valid=True\n",
    "        res=0\n",
    "        for c in s:\n",
    "            if c=='|':\n",
    "                valid=not valid\n",
    "            elif c=='*' and valid:\n",
    "                res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        valid = True\n",
    "        res = 0\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                valid = not valid\n",
    "            elif c == '*' and valid:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        start = False\n",
    "        r = 0\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                if not start:\n",
    "                    start = True\n",
    "                else:\n",
    "                    start = False\n",
    "            elif c == '*':\n",
    "                if not start:\n",
    "                    r += 1\n",
    "        return r\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        if \"*\" not in s:\n",
    "            return 0\n",
    "        s_split=s.split(\"|\")\n",
    "        result=0\n",
    "        for i in range(len(s_split)):\n",
    "            if i%2==0:\n",
    "                result=result+s_split[i].count(\"*\")\n",
    "        return result\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        legal = True\n",
    "        ans =0\n",
    "        for i in range(len(s)):\n",
    "            if legal and s[i]=='*':\n",
    "                ans+=1\n",
    "            if s[i]=='|':\n",
    "                legal = not legal\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count = 0\n",
    "        result = 0\n",
    "        for i in s:\n",
    "            if i=='|':\n",
    "                count += 1\n",
    "            elif count%2==0 and i=='*':\n",
    "                result += 1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count = 0\n",
    "        target = 0\n",
    "        for i in range (len(s)):\n",
    "            if target % 2 == 0 and s[i] == \"*\":\n",
    "                count += 1\n",
    "            if s[i] == \"|\":\n",
    "                target += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        new = []\n",
    "        lst = s.split('|')\n",
    "        for i in range(len(lst)):\n",
    "            if i%2 == 0:\n",
    "                new.append(lst[i])\n",
    "        x = ''.join(new)\n",
    "        return len(x) - len(''.join(x.split('*')))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        valid = True\n",
    "        res = 0\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                valid = not valid\n",
    "            elif c == '*' and valid:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        return sum(t.count('*') for t in s.split('|')[::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        d = s.split(\"|\")\n",
    "        count = 0\n",
    "        for i in range(0,len(d)):\n",
    "            if i % 2 == 0:\n",
    "                for j in d[i]:\n",
    "                    if j == \"*\":\n",
    "                        count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        t=''\n",
    "        for i in s:\n",
    "            if not t:\n",
    "                t+=i\n",
    "            else:\n",
    "                if t[-1]=='|' and i!='|':\n",
    "                    continue\n",
    "                elif t[-1]=='|' and i=='|':\n",
    "                    t+='1'\n",
    "                else:\n",
    "                    t+=i\n",
    "        return t.count('*')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        stop_count = False\n",
    "        res = 0\n",
    "        \n",
    "        for letter in s:\n",
    "            if not stop_count:\n",
    "                if letter == \"*\":\n",
    "                    res += 1\n",
    "                if letter == \"|\":\n",
    "                    stop_count = True\n",
    "            else:\n",
    "                if letter == \"|\":\n",
    "                    stop_count = False\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        index = 0\n",
    "        nums = 0\n",
    "        for i in s:\n",
    "            if index%2==0:\n",
    "                if i == '*':\n",
    "                   nums += 1\n",
    "                elif i == \"|\":\n",
    "                    index += 1\n",
    "            else:\n",
    "                if i == \"|\":\n",
    "                    index +=1\n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        cnt = 0\n",
    "        rst = 0\n",
    "        for i in s:\n",
    "            if cnt % 2 == 0:\n",
    "                if i == '*':\n",
    "                    rst += 1\n",
    "                elif i == '|':\n",
    "                    cnt += 1\n",
    "            else:\n",
    "                if i == '|':\n",
    "                    cnt += 1\n",
    "        return rst\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        index = nums = 0\n",
    "        for i in s:\n",
    "            if i ==\"|\":\n",
    "                index +=1\n",
    "            elif index%2==0 and i == \"*\":\n",
    "                   nums += 1      \n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "\n",
    "        res, i = 0, 0 \n",
    "        flag = True\n",
    "\n",
    "        while i < n:\n",
    "            if s[i] != '*':\n",
    "                if s[i] == '|':\n",
    "                    flag ^= True\n",
    "                i += 1\n",
    "            else:\n",
    "                j = i + 1\n",
    "                if flag:\n",
    "                    while j < n and s[j] == '*':\n",
    "                        j += 1\n",
    "                    res += j - i\n",
    "                i = j\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        s_arr = s.split(\"|\")\n",
    "        '''\n",
    "        0, 2, 4\n",
    "        '''\n",
    "        ans = 0\n",
    "        for i in range(0, len(s_arr), 2):\n",
    "            ans += s_arr[i].count(\"*\")\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count=0\n",
    "        valid = True\n",
    "        for i in s:\n",
    "            if i=='|':\n",
    "                valid= not valid\n",
    "            if i=='*' and valid:\n",
    "                count=count+1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        list1 = s.split(\"|\")\n",
    "\n",
    "        s1 = \"\"\n",
    "        for i in range(len(list1)):\n",
    "            if i%2==0:\n",
    "                s1=s1+list1[i]\n",
    "        return (s1.count('*'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        flag=False\n",
    "        count=0\n",
    "        for c in s:\n",
    "            if c=='|':\n",
    "                flag=not flag\n",
    "            if c=='*':\n",
    "                if not flag:\n",
    "                    count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        return sum(t.count('*') for t in s.split('|')[::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        lst = s.split('|')\n",
    "        res = 0\n",
    "        for i in range(0,len(lst),2):\n",
    "            res += lst[i].count('*')\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        valid = True\n",
    "        res = 0\n",
    "        for c in s:\n",
    "            if c=='|':\n",
    "                valid = not valid\n",
    "            elif c=='*' and valid:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        tag = 1\n",
    "        res = 0\n",
    "        for i in s:\n",
    "            if i == '|':\n",
    "                tag *= -1\n",
    "            if tag == 1:\n",
    "                if i == '*':\n",
    "                    res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        q=0\n",
    "        w=0\n",
    "        for i in range(len(s)):\n",
    "            if s[i]=='|':\n",
    "                q+=1\n",
    "            elif s[i]=='*' and q%2==0:\n",
    "                w+=1\n",
    "        return w\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        n=len(s)\n",
    "        countL=0\n",
    "        countS=0\n",
    "        for i in range(n):\n",
    "            if countL%2==0 and s[i]=='*':\n",
    "                countS+=1\n",
    "            if s[i]=='|':\n",
    "                countL+=1\n",
    "        return countS\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count = 0\n",
    "        stack = []\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                if stack:\n",
    "                    if stack[0] == '|':\n",
    "                        stack[:] = []\n",
    "                        continue\n",
    "                    else:\n",
    "                        count += stack.count('*')\n",
    "                        stack[:] = []\n",
    "            stack.append(c)\n",
    "        count += stack.count('*')\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        a=s.split('|')[::2]\n",
    "        x=0\n",
    "        for i in a:\n",
    "            for j in i:\n",
    "                x+=j.count('*')\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count = 0\n",
    "        stack = []\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                if stack:\n",
    "                    if stack[0] == '|':\n",
    "                        stack[:] = []\n",
    "                        continue\n",
    "                    else:\n",
    "                        count += stack.count('*')\n",
    "                        stack[:] = []\n",
    "            stack.append(c)\n",
    "        count += stack.count('*')\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans, ok = 0, 1\n",
    "        for c in s:\n",
    "            if c == '*':\n",
    "                ans += ok\n",
    "            elif c == '|':\n",
    "                ok ^= 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        stack = []\n",
    "        for ch in s:\n",
    "            if stack and ch == '|':\n",
    "                stack.pop()\n",
    "                continue\n",
    "            if not stack and ch == '|':\n",
    "                stack.append(ch)\n",
    "            elif not stack and ch == '*':\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        flag = 0\n",
    "        for ch in s:\n",
    "            if ch == '|':\n",
    "                flag ^= 1\n",
    "            if flag == 0 and ch == '*':\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        a, b, c, d=[], [], [], 0\n",
    "\n",
    "        for i in range ( len(s) ) :\n",
    "            if s[i] == \"|\" :\n",
    "                a.append(i)\n",
    "        for i in range ( 0, len(a), 2) :\n",
    "            for j in range( len(s) ) :    \n",
    "                 if a[i] < j < a[i+1] :\n",
    "                     b.append(j)       \n",
    "        for i in range ( len(s) ) :\n",
    "            if i not in b :\n",
    "                c.append( s[i] )\n",
    "        for i in c :\n",
    "            if i == \"*\" :\n",
    "                d += 1\n",
    "\n",
    "        return d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        a, b = 0, 0\n",
    "        for i in s:\n",
    "            if i == '|':\n",
    "                a += 1\n",
    "            if i == '*' and a%2 == 0:\n",
    "                b += 1\n",
    "        return b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ls=s.split('|')\n",
    "        count=0\n",
    "        for i in range(0,len(ls),2):\n",
    "             if '*' in ls[i]:\n",
    "                 count=count+ls[i].count('*')\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count = 0\n",
    "        stack = []\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                if stack:\n",
    "                    if stack[0] == '|':\n",
    "                        stack[:] = []\n",
    "                        continue\n",
    "                    else:\n",
    "                        count += stack.count('*')\n",
    "                        stack[:] = []\n",
    "            stack.append(c)\n",
    "        count += stack.count('*')\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        count: int = 0\n",
    "        iscollecting: bool = True\n",
    "\n",
    "        for char in s:\n",
    "            if char == '|':\n",
    "                iscollecting = not iscollecting\n",
    "                continue\n",
    "            \n",
    "            if iscollecting and char == '*':\n",
    "                count += 1\n",
    "        return count "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        slist=s.split(\"|\")\n",
    "        list1=[]\n",
    "        for i in range(len(slist)):\n",
    "            if i%2==0:\n",
    "                ans1=list(slist[i]).count(\"*\")\n",
    "                list1.append(ans1)\n",
    "        return sum(list1)\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans, flag = 0, True\n",
    "        for c in s:\n",
    "            if c == '*' and flag:\n",
    "                ans += 1\n",
    "            elif c == '|':\n",
    "                flag = not flag\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        symb = 0\n",
    "        count = 0\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                symb += 1\n",
    "            if symb % 2 == 0 and c == '*':\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans = 0\n",
    "        is_count = True\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                is_count = not is_count\n",
    "            \n",
    "            if is_count and c == '*':\n",
    "                ans += 1\n",
    "\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ans, flag = 0, True\n",
    "        for c in s:\n",
    "            if flag and c == '*': ans += 1\n",
    "            elif c =='|': flag = not flag\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        flag=1\n",
    "        ans=0\n",
    "        for i in s:\n",
    "            if i =='*':\n",
    "                ans=ans+flag\n",
    "            elif i =='|':\n",
    "                flag=(flag+1)%2\n",
    "        return ans\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        s = s.split(\"|\")\n",
    "        count = 0\n",
    "        for i in range(0,len(s),2):\n",
    "            for j in s[i]:\n",
    "                if j == \"*\":\n",
    "                    count += 1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        cnt = 0\n",
    "        betw = False\n",
    "\n",
    "        for ch in s:\n",
    "            if not betw and ch == \"*\":\n",
    "                cnt += 1\n",
    "            elif ch==\"|\":\n",
    "                betw = not betw\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        res = 0\n",
    "        a = s.split(('|'))\n",
    "        for i in range(0, len(a), 2):\n",
    "            res += a[i].count('*')\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countAsterisks(self, s: str) -> int:\n",
    "        ct = 0\n",
    "        flag = 0\n",
    "        for c in s:\n",
    "            if c == '|':\n",
    "                flag += 1\n",
    "                continue\n",
    "            \n",
    "            if c == '*' and flag % 2 == 0:\n",
    "                ct += 1\n",
    "\n",
    "        return ct\n",
    "\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
